package com.lighthouse.base.common.controller;

import java.text.DateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.lighthouse.base.common.service.SimpleService;
import com.lighthouse.base.common.vo.*;

@Controller
public class BaseController {
	
	private static final Logger logger = LoggerFactory.getLogger(BaseController.class);
	
    @Resource (name="SimpleService")
    private SimpleService simpleService;
    
	@RequestMapping(value = "/baseInfo", method = RequestMethod.GET)
	public String baseInfo(Locale locale, Model modelMap, HttpSession sess) {
		logger.info("Welcome home! the client locale is "+ locale.toString());
		
		// Get Date, time
		Date date = new Date();
		DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
		String formattedDate = dateFormat.format(date);
		
		// Get DB data
		List<SimpleVO> simpleVoList = null;
		simpleVoList = simpleService.getSimpleList();
		modelMap.addAttribute("ContentList", simpleVoList);
		
		if(logger.isDebugEnabled()) logger.debug("baseInfo Test is OK!!!");
		
		//Set Model Info
		sess.setAttribute("skin", "skin-default");
		modelMap.addAttribute("serverTime", formattedDate );
		modelMap.addAttribute("ContentList", simpleVoList);
		
		return "baseInfo";
	}
	
}
